<?php 
namespace Admin\Controller;
use Think\Controller;
class TypeController extends BaseController{
	function type(){
		$typeOb=M('Wares_type');
        $count = $typeOb->count();
        $Page = new \Think\Page($count,4);
        $show = $Page->show();
        $this->assign('show',$show);
		$arr=$typeOb->select();
		function oneps($hz,$pid=0,$level=1){
				//返回onepsall
				$onepsall = array();
				foreach($hz as $v){
					if($v['pid']==$pid){
						$v['level'] = $level;
						$v['html']=str_repeat('&nbsp',($level*5));
						$onepsall[] = $v;
						//oneps($hz,$pid=$v['id'],$level+1)
						$onepsall = array_merge($onepsall,oneps($hz,$v['id'],$level+1));
					}
				}
				return $onepsall;
         }    
         $array = oneps($arr);
		$this->assign('arr',$array);
		$this->display();
	}
	function check(){
			if (!empty($_POST)) {
				 $waresTypeOb=M('Wares_type');
				 $cRe=$waresTypeOb->create();
				if ($cRe) {
					 $re=$waresTypeOb->add();
					 if ($re) {
					 	  $this->success("添加成功",U("Admin/Type/type"));
					 }else{
					 	$this->erroy("添加失败",U("Admin/Type/type"));
					 }
					 exit();
				}else{
					$info=$waresTypeOb->getError();
					//$this->assign('info',$info);
					//$this->assign('arr',$_POSt);
					//$infoStr = join('<br>',$info);
					$this->error($info,U("Admin/Type/type"),1);
				}
			}
	}
	function censor(){
	  $waresTypeOb=M('Wares_type');
	  $cRe=$waresTypeOb->create();
	  if ($cRe) {
		$re=$waresTypeOb->add();
		 if ($re) {
			echo 1;
		}
	  }else{
	  	 $info = $waresTypeOb->getError();
	  	 echo json_encode($info);
	  }
	  /*	$typeSon=$waresTypeOb->where('$_POST['pid']')->select();
	  	$this->assign('typeSon',$typeSon);*/
	}	
	function type_del(){
		$ectryOb=D('Wares_type');
		$arr=$ectryOb->where("id = {$_GET['id']}")->delete();
		if ($arr) {
			echo 1;
		}else{
			echo 0;
		}
	}
}